// pages/order_det/order_det.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: '',
    isMB: false,
    goodsId: '',
    type: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log(options)
    this.setData({
      id: options.id
    })

  },
  confirm() {
    app.req('purchasingOrderForm/allDone/' + this.data.id, '', 'PUT', res => {
      if (res.data.code == 200) {
        wx.showToast({
          title: res.data.msg
        })
      } else {
        wx.showToast({
          icon: 'none',
          title: res.data.errorMsg,
        })
      }
    })
  },
  add() {
    wx.navigateTo({
      url: '/pages/purchasing_order/purchasing_order?id=' + this.data.id
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.getList()
  },
  getList(){
    var that = this
    app.req('productionOrderForm/' + this.data.id, '', 'GET', res => {
      console.log(res)
      that.setData({
        list: res.data.data,
        // estimatedFinishTime: res.data.data.productionOrderForm.estimatedFinishTime.split(' ')[0]
      })
    })
  },

  sign(e) {
    console.log(e)
    this.setData({
      isMB: true,
      goodsId: e.currentTarget.dataset.id,
      type: e.currentTarget.dataset.name
    })
  },
  deMB() {
    this.setData({
      isMB: false
    })
  },
  z_Submit(e) {
    // switch (e.detail.target.dataset.name) {
    //   case '品牌':
    //     this.data.brand.push(e.detail.value.add)
    //     break
    //   case '尺码':
    //     this.data.size.push(e.detail.value.add)
    //     break
    //   case '颜色':
    //     this.data.colour.push(e.detail.value.add)
    //     break
    // }
    var that = this
    var data1 = {
      businessOrderFormId: this.data.list.businessOrderFormId,
      purchasingOrderFormId: this.data.list.purchasingOrderFormId,
      fabricList: [{
        id: this.data.goodsId,
        fabricConfirmQuantity: e.detail.value.addNum,
        fabricCallBackRemark: e.detail.value.addRe,
      }]
    }
    var data2 = {
      businessOrderFormId: this.data.list.businessOrderFormId,
      purchasingOrderFormId: this.data.list.purchasingOrderFormId,
      fabricList: [{
        id: this.data.goodsId,
        fabricDoneQuantity: e.detail.value.addCNum
      }]
    }
    if (this.data.type == '签收') {
      app.req('productionOrderForm/confirmFabric/' + this.data.id, data1, 'PUT', res => {
        console.log(res)
        if(res.data.code == 200){
          wx.showToast({
            title: res.data.msg,
          })
          that.getList()
        }else{
          wx.showToast({
            icon:'none',
            title: res.data.errorMsg,
          })
        }
      })
    } else {
      app.req('productionOrderForm/pruneClothing/' + this.data.id, data2, 'PUT', res => {
        console.log(res)
        if (res.data.code == 200) {
          wx.showToast({
            title: res.data.msg,
          })
          that.getList()
        } else {
          wx.showToast({
            icon: 'none',
            title: res.data.errorMsg,
          })
        }
      })
    }



    this.setData({
      brand: this.data.brand,
      size: this.data.size,
      colour: this.data.colour,
      isMB: false
    })
  },
  deliver: (e) => {
    wx.navigateTo({
      url: '/pages/deliver/deliver?id=' + e.currentTarget.dataset.id
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})